package com.cloudcms.web.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.cloudcms.web.util.Constants;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;



public class Result extends HashMap{
	Map<String, Object>  map = new HashMap<String, Object>();
	private String msg = "SYSERR_OK";
	private long code = Constants.SIMPLE_RESULT_SUCCESS;
	private Map getResult() {
		map.put("msg",msg);
		map.put("code",code);
		return map;
	}
	public void setCode(long code) {
		this.code = code;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	public static final ValueFilter FILTER = new ValueFilter() {
		@Override
		public Object process(Object obj, String s, Object value) {
			if(value==null) return "";
			return value;
		}
	};
	public Object put(Object key, Object value){
		if(!(value instanceof List)){
			List list = new ArrayList();
			list.add(value);
			super.put(key,list);
		}else{
			super.put(key,value);
		}
		return  value;
	};
	/*public V append(K key,V value){
		if(!(value instanceof List)){
			List<V> list = new ArrayList<V> ();
			list.add(value);
			this.put(key,list);
		}else{
			this.put(key,value);
		}
		return  value;
	}*/
	@Override
	public String toString() {
		//return super.toString();
		this.put("result",getResult());
		return JSON.toJSONString(this,FILTER,SerializerFeature.WriteMapNullValue);
	}
	public  static  void main(String[] args){
		List list = new ArrayList();
		System.out.println(list instanceof ArrayList);
	}
}